<%-- <%@page import="common.SerialDTO"%>
<%@page import="common.SerialDAO"%> --%>
<%@page import="java.util.List"%>
<%@page import="code.CodeDAO"%>
<%@page import="code.CodeDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	request.setCharacterEncoding("UTF-8");
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 모바일 사용자를 위해 viewport 추가-->
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
<!--모바일 기기에서 확대/축소 불가<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
콘텐츠 중앙으로 가져오기<div class="container">...</div>-->
<title></title>
<style type="text/css">
th{
 background-color: #e5e5e5;
}
</style>
<!-- bootstrap -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0-wip/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/intranet/css/bootstrap.css">
<!-- DateTimePicker -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/intranet/css/jquery.datetimepicker.css" />
<script src="${pageContext.request.contextPath }/intranet/js/jquery.datetimepicker.js"></script>
<script src="${pageContext.request.contextPath }/intranet/js/searchbox.js"></script>
<script>
	jQuery(function() {
		$("#cd_schText").keypress(function(event){
			//alert(event.which);
			if(event.which == 13){
				//alert("엔터쳤구만요?");
				cd_list_srch();
			}
		});
		
		// SELECTPICKER
		$('.selectpicker').selectpicker({
			"width" : "100px"
		});
		 // DATETIMEPICKER
		jQuery('#date_timepicker_start').datetimepicker(
				{
					format : 'Y/m/d',
					onShow : function(ct) {
						this
								.setOptions({
									maxDate : jQuery('#date_timepicker_end')
											.val() ? jQuery(
											'#date_timepicker_end').val()
											: false
								});
					},
					timepicker : false
				});
		jQuery('#date_timepicker_end').datetimepicker(
				{
					format : 'Y/m/d',
					onShow : function(ct) {
						this
								.setOptions({
									minDate : jQuery('#date_timepicker_start')
											.val() ? jQuery(
											'#date_timepicker_start').val()
											: false
								});
					},
					timepicker : false
				});
	});
	function btnApNoSrch() {
		alert("초기화합니다.");
	}
	function openViewWindow() {
		window.open("ap_list_popup.jsp", "_blank", "resizable=yes, top=100, left=200, width=600, height=650");
	}
	
	// 테이블 ROW 클릭하면 상세화면에 값 입력
	function test(grp1, grp1nm, grp2, grp2nm, cd, st, rp, rd, mp, md){
		$('#grp1').val(grp1);$('#grp1_nm').val(grp1nm);
		$('#grp2').val(grp2);$('#grp2_nm').val(grp2nm);
		$('#cd_cd').val(cd);$('#cd_st').val(st);
		$('#rg_pp').val(rp);$('#rg_dt').val(rd);
		$('#md_pp').val(mp);$('#md_dt').val(md);
		document.getElementById("grp1").disabled = true;
	}
	// 초기화 버튼 눌렀을 때
	function initialize(){
		$('#grp1').val("");
		$('#grp1_nm').val("");
		$('#grp2').val("");
		$('#grp2_nm').val("");
		$('#cd_cd').val("");
		$("#cd_st").html("<option>분류선택</option><option>Y</option><option>N</option></select>");
		$('#rg_pp').val("");
		$('#rg_dt').val("");
		$('#md_pp').val("");
		$('#md_dt').val("");
		document.getElementById("grp1").disabled = false;
	}
	// 등록 버튼 눌렀을 때
	function insert(){
		var url = "${pageContext.request.contextPath}/intranet/index.jsp?inc_content=./code/cd_insert.jsp";
		var params = "cd_grp1=" + $('#grp1').val();
		params=params+"&cd_grp1_nm="+$('#grp1_nm').val();
		params=params+"&cd_grp2_nm="+$('#grp2_nm').val();
		params=params+"&cd_st="+$("#cd_st option:selected").val(); 
		//alert(params); 
	    
		 $.ajax({  
	        type: 'POST'  
	        ,url: url  
	        ,data: params
	        ,success: function (){
	    		$('#tb_cdList').load("${pageContext.request.contextPath}/intranet/index.jsp?inc_content=./code/cd_list_crud.jsp #tb_cdList");
	    		alert("등록되었습니다.");
	    		initialize();
	    	}
	        ,error:function(request,status,error){
	            alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
	        }
	      });   
	      
	}
	// 수정 버튼 눌렀을 때
	function update(){
		var url = "${pageContext.request.contextPath}/intranet/index.jsp?inc_content=./code/cd_update.jsp";
		var params = "cd_grp1=" + $('#grp1').val();
		params=params+"&cd_grp1_nm="+$('#grp1_nm').val();
		params=params+"&cd_grp2="+$('#grp2').val();
		params=params+"&cd_grp2_nm="+$('#grp2_nm').val();
		params=params+"&cd_st="+$("#cd_st option:selected").val(); 
		//alert(params); 
	    
		 $.ajax({  
	        type: 'POST'  
	        ,url: url  
	        ,data: params
	        ,success: function(){
	        	//$('#tb_cdList').load("${pageContext.request.contextPath}/intranet/index.jsp?inc_content=./code/cd_list_crud.jsp #tb_cdList");
	        	cd_list_srch();
	        	alert("수정되었습니다.");
	        }
	        ,error:function(request,status,error){
	            alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
	        }
	      });
	}
	// 조회 버튼 눌렀을 때
	function cd_list_srch(){
		if($('#cd_schText').val() == ""){
			alert("검색어를 입력해주세요.");
			return;
		}
		//alert("조회눌렀구만요?");
		var url = "${pageContext.request.contextPath}/intranet/code/cd_srch.jsp";
		var find ="";
		find = $('#cd_schText').val();
		//alert(find);
		var params = "srchWord=" + find;
		 
		$.ajax({
			  type: 'POST'
			, url : url
			, data : params
			, success: function(testList){
				//testList="qqqqqq";
	        	//alert(testList);
	        	$('#tableDiv').html(testList);
				//initialize();
				//$('#tb_cdList').load("${pageContext.request.contextPath}/intranet/index.jsp?inc_content=./code/cd_list_crud.jsp #tb_cdList");
			}
			, error:function(request,status,error){
	            alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
	        }
		});
	}
	
</script>
</head>
<body>
<jsp:useBean id="dto" class="code.CodeDTO" />
<jsp:setProperty property="*" name="dto"/>
<%
/* CodeDAO code4List = new CodeDAO();
code4List.setDto(dto);
List<CodeDTO> codeList = code4List.cdSrch(dto.getSrchWord()); 
System.out.println("aa"); 
System.out.println("srchw : "+dto.getSrchWord());  */

/* CodeDAO code4insert = new CodeDAO();
code4insert.setDto(dto); */

// insert test ========================================= //
/* dto.setCd_grp1("APING");
dto.setCd_grp1_nm("test");
dto.setCd_grp2_nm("test");
int yn = code4insert.insert();
System.out.println("화면단인데.. insert 됐낭~? : "+yn); */
//===================================================== //

// 로그인한 session값 체크
/* session.setAttribute("mid", "Admin"); */
String id = (String)session.getAttribute("mid");
//System.out.print("sessionID : "+id);

%>
	<!-- 제목1 -->
	<h1 style="text-align: center;">
		공통코드내역<small>Code List</small>
	</h1>

	<!-- CRUD 메뉴 -->
	<div align="right" style="margin: 20px 200px 20px auto;">
		<button class="btn btn-danger" type="button" onclick="initialize()">
			<span class="glyphicon glyphicon-refresh">&nbsp;</span>초기화
		</button>
		<button id="btnInsert" class="btn btn-primary" type="button"
			onclick="insert()">등록</button>
		<button id="btnUpdate" class="btn btn-warning" type="button"
			onclick="update()">수정</button>
	<form class="form-inline" id="cd_list_srch">
		<div class="form-group" align="right"
			style="margin: 10px 5px auto auto; width: 180px;">
				<input type="search" class="form-control" placeholder="업무대분류/대분류명" id="cd_schText">
		</div>
			<button id="btnSrchDetail" class="btn btn-success" type="button"
				onclick="cd_list_srch()" style="margin: 10px 0px auto auto;">조회</button>
	</form>
	</div>



	<!-- 테이블 영역 -->
	<div align="center">
	<p>업무대분류 또는 대분류명으로 조회해주세요. 예) CTING, SADP, 직급, 부서, 계약 등..</p>
	</div>
	<div id="tableDiv" align="center">
	<%-- <table class="table" id="tb_cdList"
		style="width: 1200px; margin: 20px auto 10px auto;">
		<thead style="background-color: #e5e5e5;">
			<tr>
				<!-- <th>선택</th> -->
				<th>업무대분류</th>
				<th>업무소분류</th>
				<th>코드</th>
				<th>등록자</th>
				<th>등록일</th>
				<th>수정자</th>
				<th>수정일</th>
				<th>사용여부</th>
			</tr>
		</thead>
		<tbody class="table table-hover" align="center" id="cd_tbody">
				<%
				for(int i=0; i<codeList.size(); i++){
					CodeDTO tableRow = codeList.get(i);
				%>	
			<tr id="<%=tableRow.getCd_grp1() %><%=tableRow.getCd_grp2() %>" onclick="test('<%=tableRow.getCd_grp1() %>'
																						 , '<%=tableRow.getCd_grp1_nm() %>'
																						 , '<%=tableRow.getCd_grp2() %>'
																						 , '<%=tableRow.getCd_grp2_nm() %>'
																						 , '<%=tableRow.getCd_grp1() %><%=tableRow.getCd_grp2() %>'
																						 , '<%=tableRow.getCd_st() %>'
																						 , '<%=tableRow.getRg_pp() %>'
																						 , '<%=tableRow.getRg_dt() %>'
																						 , '<%=tableRow.getMd_pp() %>'
																						 , '<%=tableRow.getMd_dt() %>')">
				<!-- <td><input type="radio"></td> -->
				<td><%=tableRow.getCd_grp1_nm() %></td>
				<td><%=tableRow.getCd_grp2_nm() %></td>
				<td><%=tableRow.getCd_grp1() %><%=tableRow.getCd_grp2() %></td>
				<td><%=tableRow.getRg_pp() %></td>
				<td><%=tableRow.getRg_dt() %></td>
				<td><%=tableRow.getMd_pp() %></td>
				<td><%=tableRow.getMd_dt() %></td>
				<td><%=tableRow.getCd_st() %></td>
			</tr>
				<%}%>
		</tbody> 
	</table> --%>
	</div>
	
	<hr/>
	<!-- 제목2 -->
	<h1 style="text-align: center;">
		공통코드상세<small>Code Detail</small>
	</h1>
	
	<!-- 테이블 영역 -->
	<table class="table"
		style="width: 900px; margin: 30px auto;">
		<thead>
			<tr>
				<th style="vertical-align: middle;">업무대분류</th>
				<td><input type="text" class="form-control" id="grp1" size="5" placeholder="업무대분류">&nbsp;&nbsp;
				    <input type="text" class="form-control" id="grp1_nm" placeholder="대분류명"></td>
				<th style="vertical-align: middle;">등록자</th>
				<td style="vertical-align: middle;"><input type="text" class="form-control" id="rg_pp" readonly="readonly"></td>
			</tr>
			<tr>
			</tr>
			<tr>
				<th style="vertical-align: middle;">업무소분류</th>
				<td><input type="text" class="form-control" id="grp2" size="5" readonly="readonly" placeholder="업무소분류">&nbsp;&nbsp;
				    <input type="text" class="form-control" id="grp2_nm"placeholder="소분류명"></td>
				<th style="vertical-align: middle;">등록일</th>
				<td style="vertical-align: middle;"><input type="text" class="form-control" id="rg_dt" readonly="readonly"></td>
			<tr>
			</tr>
			<tr>
				<th style="vertical-align: middle;">코드</th>
				<td><input type="text" class="form-control" id="cd_cd" readonly="readonly" placeholder="코드" ></td>
				<th style="vertical-align: middle;">수정자</th>
				<td><input type="text" class="form-control" id="md_pp" readonly="readonly"></td>
			</tr>
			<tr>
			</tr>
			<tr>
				<th style="vertical-align: middle;">사용여부</th>
				<td><select class="form-control" id="cd_st"><option selected="selected">분류선택</option><option>Y</option><option>N</option></select></td>
				<th style="vertical-align: middle;">수정일</th>
				<td><input type="text" class="form-control" id="md_dt" readonly="readonly"></td>
			</tr>
		</thead>
	</table>
</body>

</html>